# -*- mode: ruby -*-
# vi: set ft=ruby :
#
# Vagrantfile.dual-provider.tomcat - Install Bigdata under Tomcat with an either a VirtualBox (Default) or AWS Provider
#
# The launch synopsis for this Vagrantfile:
#
#   VirtualBox provider:
#
#   % vagrant up
#
#   AWS provider:
#
#   % source ./aws.rc
#   % vagrant up --provider=aws
#

Vagrant.require_plugin "vagrant-berkshelf"

Vagrant.configure("2") do |config|
  #
  # By default, the VirtualBox provider will be launched.
  # Defaults are set for the VirtualBox assumption.
  #
  config.vm.box = "precise64"
  config.vm.hostname = "bigdata"

  config.berkshelf.enabled = true

  config.vm.provider :virtualbox do |vb|
    vb.vm.box_url = "http://files.vagrantup.com/precise64.box"

    vb.vm.network :private_network, ip: "33.33.33.10"
  end

  #
  # The AWS provider will be used specified at the command line as per:
  # %  vagrant up --provider=aws
  #
  config.vm.provider :aws do |aws, override|
    override.vm.box = "dummy"
    aws.access_key_id = ENV['AWS_ACCESS_KEY_ID']
    aws.secret_access_key = ENV['AWS_SECRET_ACCESS_KEY']
    aws.keypair_name = ENV['AWS_KEYPAIR_NAME']

    aws.ami = ENV['AWS_AMI']
    
    aws.region = ENV['AWS_REGION']
    aws.instance_type = ENV['AWS_INSTANCE_TYPE']
    aws.security_groups = [ ENV['AWS_SECURITY_GROUPS'], ENV['AWS_SECURITY_GROUP_PRIVATE'] ]

    aws.tags = {
      'Name' => ENV['BIGDATA_HA_HOST_A']
    }

    override.ssh.username = ENV['AWS_AMI_USERNAME']
    override.ssh.private_key_path = ENV['AWS_SSH_PRIVATE_KEY']
  end


  config.vm.provision :chef_solo do |chef|
    chef.json = {
	:bigdata => {
	 	:install_flavor => "tomcat",
	 	:build_from_svn => false
	},
	:java => {
		:install_flavor => "oracle",
		:jdk_version => "7",
		:oracle => { 'accept_oracle_download_terms' => true }
	},
	:tomcat => {
	 	:base_version => "7"
	}
    }

    config.vm.provision :shell, inline: "sudo apt-get update ; sudo curl -L https://www.opscode.com/chef/install.sh | sudo bash"

    chef.run_list = [
        "recipe[bigdata::tomcat]"
    ]

  end
end
